home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group98a.txt
/
000053_icon-group-sender _Tue Feb 24 13:03:47 1998.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
5KB
Return-Path: <icon-group-sender>
Received: from kingfisher.CS.Arizona.EDU (kingfisher.CS.Arizona.EDU [192.12.69.239])
by baskerville.CS.Arizona.EDU (8.8.7/8.8.7) with SMTP id NAA05066
for <icon-group-addresses@baskerville.CS.Arizona.EDU>; Tue, 24 Feb 1998 13:03:47 -0700 (MST)
Received: by kingfisher.CS.Arizona.EDU (5.65v4.0/1.1.8.2/08Nov94-0446PM)
id AA28149; Tue, 24 Feb 1998 13:03:46 -0700
Date: Tue, 24 Feb 1998 09:02:13 -0800
From: kwalker@sfo.harbinger.com (Ken Walker)
Message-Id: <199802241702.JAA12855@varda.premenos.com>
To: icon-group@optima.CS.Arizona.EDU, khemlann@agcs.com
Subject: Re: icon questions
Cc: khemlann@agcs.com
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Md5: S1D7bHFkzLcfAXlHKsMdjg==
Errors-To: icon-group-errors@optima.CS.Arizona.EDU
Status: RO
Content-Length: 4424
> Date: Tue, 17 Feb 1998 00:26:47 -0700
> From: khemlann@agcs.com (Neil Khemlani)
>
> Actually, I have two main questions. First, is there a flag that I can
> use with iconx or iconc that will allow it to produce C source code?
The -c option of iconc will produce C source code. However, the source
code is only suitable for compiling and linked to a run-time system. It
is not meant for human consumption. As an example, I translated
a simple "hello, world" program. It produced two files. The .h file
is
/*ICONC*/
/*
* Tue Feb 24 08:12:11 1998
* This file was produced by
* iconc: Icon Compiler Version 9.0. July 16, 1994
*/
#define COMPILER 1
#include "/home/users/edison/kwalker/icon_v9.0/bin_solaris/rt.h"
#define OpTblSz 1
int op_tbl_sz = 0;
#define NGlobals 1
int n_globals = 0;
int n_statics = 0;
struct descrip statics[1];
int F291_write Params((word status , FILE *f , dptr x , int nargs , dptr
rslt));
hidden int P000_main Params((noargs));
struct PF000_main {
struct p_frame *old_pfp;
dptr old_argp;
dptr rslt;
continuation succ_cont;
struct {
struct tend_desc *previous;
int num;
struct descrip d[1];
} tend;
};
and the .c file is
/*ICONC*/
/*
* Tue Feb 24 08:12:11 1998
* This file was produced by
* iconc: Icon Compiler Version 9.0. July 16, 1994
*/
#include "t1.h"
static B_IProc(2) init_op_tbl[OpTblSz];
static struct {word dword; union block *vword;} init_globals[NGlobals] = {
{D_Null} /* place holder */
};
struct sdescrip init_gnames[1];
struct b_proc *builtins[1];
int main(argc, argv)
int argc;
char **argv;
{
op_tbl = (struct b_proc *)init_op_tbl;
globals = (dptr)init_globals;
eglobals = &globals[0];
gnames = (dptr)init_gnames;
egnames = &gnames[0];
estatics = &statics[0];
debug_info = 0;
line_info = 0;
err_conv = 0;
largeints = 0;
init(*argv, &argc, argv, 0);
tend = NULL;
P000_main();
c_exit(NormalExit);
}
static int P000_main()
{
struct PF000_main r_frame;
register int r_signal;
int i;
r_frame.old_pfp = pfp;
pfp = (struct p_frame *)&r_frame;
r_frame.old_argp = argp;
r_frame.rslt = NULL;
r_frame.succ_cont = NULL;
for (i = 0; i < 1; ++i)
r_frame.tend.d[i] = nulldesc;
argp = NULL;
r_frame.tend.num = 1;
r_frame.tend.previous = tend;
tend = (struct tend_desc *)&r_frame.tend;
Poll();
r_frame.tend.d[0].vword.sptr = "hello, world";
r_frame.tend.d[0].dword = 12;
Poll();
Poll();
{
FILE *f = NULL;
word status =
k_output.status;
if ((k_output.status & Fs_Write) == 0 )
goto L1 /* within: write */;
f= k_output.fd;
goto L2 /* within: write */;
L1: ; /* within: write */
err_msg(213, NULL);
L2: ; /* within: write */
F291_write(status, f, (&r_frame.tend.d[0]), 1, &trashcan);
}
Poll();
tend = r_frame.tend.previous;
pfp = r_frame.old_pfp;
argp = r_frame.old_argp;
return A_Resume;
}
More complex programs only get worse...
There are several problems with translating Icon into C. Some of
the major problems are:
- you must implement goal-directed evaluation in a laguage
that has none. In some cases, with enough optimization, it
can be converted into loops. But in other cases the best
technique we have come up with involves breaking the program
into lots of little functions and passing function pointers
around everywhere. This is not your typical C code.
- variables must be able to hold any value, and values must include
type information. In some cases, if you do enough analysis, you
can remove these requirements, but in general you cannot.
- variables have to be implemented in such as way that the garbage
collector can find them.
Converting Icon programs into C is much more interesting than it
appears on the surface :-)
Ken Walker, kwalker@sfo.harbinger.com
Harbinger Coporation, Concord, Ca. 94520